package cn.com.bsoft.mobile.dao

import cn.com.bsoft.mobile.entity.MobileApp
import cn.com.bsoft.mobile.entity.MobileAppVersion
import cn.net.xyan.blossom.core.support.EasyJpaRepository

import org.springframework.data.domain.Pageable
import org.springframework.data.jpa.repository.Modifying
import org.springframework.data.jpa.repository.Query
import java.util.*

interface VersionDao: EasyJpaRepository<MobileAppVersion, String> {

    @Query("select v from MobileAppVersion v where v.app = ?1 and v.type = ?2 and v.enable = true")
    fun queryAvailableVersion(app:MobileApp,type:String,page:Pageable):List<MobileAppVersion>

    @Query("select v from MobileAppVersion v where v.app = ?1 and v.type = ?2 and v.version = ?3")
    fun queryVersion(app:MobileApp,type:String,version:String):List<MobileAppVersion>

    @Query("select v from MobileAppVersion v where v.app = ?1 and v.type = ?2 and v.version = ?3")
    fun queryVersion(app:MobileApp,type:String,version:String,page:Pageable):List<MobileAppVersion>

    @Query("select v from MobileAppVersion v join v.app a  where a.nativeID = ?1 and v.type = ?2")
    fun queryVersion(appID:String,type:String):List<MobileAppVersion>

    @Query("select v from MobileAppVersion v join v.app a  where a.nativeID = ?1")
    fun queryVersion(appID:String):List<MobileAppVersion>

    @Query("select v from MobileAppVersion v where v.app = ?1 and v.createDate <= ?2")
    fun queryVersion(app:MobileApp,createTime: Date):List<MobileAppVersion>

    @Modifying
    @Query("update MobileAppVersion v set v.enable = ?1 where v = ?2")
    fun updateEnable(enable:Boolean,version:MobileAppVersion)
}